/*
 * @Author:  
 * @Date: 2018-07-08 22:22:53 
 * @describe: 自己写的代码 bus代码
 * @Last Modified by: angelpig
 * @Last Modified time: 2018-07-08 22:23:16
 */


var Pubsub = function () {
    this._Events = {};
} 
Pubsub.prototype = {
    constructor:Pubsub,
    on : function (event, callback) {
        if (typeof event !== "string" || typeof callback !== "function") return;
        var _Events = this._Events;
        if (!_Events[event]) _Events[event] = [];
        _Events[event].push(callback);
    }, 
    trigger : function (type) {
        if (typeof type !== "string") return false;
        var _Events = this._Events;
        var params = Array.prototype.slice.call(arguments, 1);
        if (_Events[type] && _Events[type].length > 0) {
            for (var i = 0; i < _Events[type].length; i++) {
                _Events[type][i].apply(this, params);
            }
        }

    },
    off : function (type) {
        if (typeof type !== "string") return false;
        var _Events = this._Events;
        if (_Events[type]) {
            delete _Events[type];
        }
    }
}
export default new Pubsub;